<?php
    $select_m=mysql_query('SELECT * FROM messages WHERE `from`="'.$_SESSION['username'].'" ORDER BY date DESC');
	if(mysql_num_rows($select_m)>0){
	
	echo '
	<table border="0" style="border-collapse: collapse; margin-left: 70px;">
	<tr style="background-color: #ddd;"><td style="width: 150px;" align="center"><p><b>Тема</b></p></td><td style="width: 70px;" align="center"><p><b>До</b></p></td><td style="width: 100px;" align="center"><p><b>Изпратено</b></p></td><td style="width: 200px;" align="center"><p><b>Съобщение</b></p></td></tr>
	<tr><td></td></tr><tr><td></td></tr><tr><td></td></tr>
	';
	while($row_m=mysql_fetch_assoc($select_m)){
	if($row_m['unread']==1){
	echo '<tr><td style="padding-left: 10px;"><b>'.$row_m['topic'].'</b></td>
	<td style="text-align: center"><b>'.$row_m['to'].'</b></td><td style="text-align: center">
	<b>'.date('d-m-Y', $row_m['date']).'</b></td><td style="padding-right: 10px; text-align: center;">
	<a href="view/index.php?id='.$row_m['id'].'&amp;mode=view&amp;in=out" class="message">Виж </a>
	</td></tr>
	<tr><td colspan="4" style="padding-left: 10px; padding-right: 10px;"><hr /></td></tr>';
	}
	else{
	echo '<tr><td style="padding-left: 10px;">'.$row_m['topic'].'</td><td style="text-align: center">'.$row_m['to'].'</td>
	<td style="text-align: center">'.date('d-m-Y', $row_m['date']).'</td><td style="padding-right: 10px; text-align: center;">
	<a href="view/index.php?id='.$row_m['id'].'&amp;mode=view&amp;in=out" class="message">Виж </a>
	</td></tr>
	<tr><td colspan="4" style="padding-left: 10px; padding-right: 10px;"><hr /></td></tr>';
	}
	}
	echo '
	</table>
	';
	}
	else{
	   echo "<p style='text-align: center; font-weight: bold;'>Няма съобщения</p>";
	}
?>